package com.newcoin.xgb.controller;

import com.newcoin.xgb.dto.BuyFinManDto;
import com.newcoin.xgb.dto.QueryParameterDto;
import com.newcoin.xgb.entity.Result;
import com.newcoin.xgb.entity.XgbFinancialCycle;
import com.newcoin.xgb.entity.XgbFinancialProduct;
import com.newcoin.xgb.po.FinancialOrderPo;
import com.newcoin.xgb.po.YebBalancePo;
import com.newcoin.xgb.service.YebService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@Slf4j
@RequestMapping(value = "/xgb")
@Api(description = "首页余额宝接口")
public class YebController {

    @Autowired
    private YebService service;

    @ApiOperation(value = "首页推荐理财周期列表")
    @GetMapping(value = "/getFinMan")
    public Result<List<XgbFinancialProduct>> getFinMan() {
        try {
            return service.getFinMan();
        } catch (Exception e) {
            log.error(e.getMessage());
            Result<List<XgbFinancialProduct>> result = new Result<>();
            result.setCode(500);
            result.setMessage("获取理财产品失败");
            return result;
        }
    }

    @ApiOperation(value = "档次列表")
    @ApiImplicitParams(
            {
                    @ApiImplicitParam(name = "cycleId", value = "周期Id", required = true, dataType = "String")
            }

    )
    @GetMapping(value = "/getFinancialProductList")
    public Result<List<XgbFinancialProduct>> getFinancialProductList(Integer cycleId) {
        try {
            return service.getFinancialProductList(cycleId);
        } catch (Exception e) {
            log.error(e.getMessage());
            Result<List<XgbFinancialProduct>> result = new Result<>();
            result.setCode(500);
            result.setMessage("获取理财产品失败");
            return result;
        }
    }


    @ApiOperation(value = "购买理财")
    @ApiImplicitParams(
            {
                    @ApiImplicitParam(name = "userId", value = "用户id", required = true, dataType = "String"),
                    @ApiImplicitParam(name = "token", value = "token", required = true, dataType = "String"),
                    @ApiImplicitParam(name = "amount", value = "转入金额", required = true, dataType = "String"),
                    @ApiImplicitParam(name = "productId", value = "产品类型 产品id", required = true, dataType = "int"),
                    @ApiImplicitParam(name = "payPwd", value = "交易密码", required = true, dataType = "String"),
            }
    )
    @PostMapping(value = "/buyFinMan")
    public Result buyFinMan(BuyFinManDto buyFinMan) {
        try {
            return service.buyFinMan(buyFinMan);
        } catch (Exception e) {
            log.error(e.getMessage());
            Result result = new Result<>();
            result.setCode(500);
            result.setMessage("转入失败");
            return result;
        }
    }


    @ApiOperation(value = "获取余额宝余额")
    @ApiImplicitParams(
            {
                    @ApiImplicitParam(name = "userId", value = "用户id", required = true, dataType = "String"),
                    @ApiImplicitParam(name = "token", value = "token", required = true, dataType = "String"),
                    @ApiImplicitParam(name = "忽略非必填字段", value = "", required = false)
            }
    )
    @GetMapping(value = "/getYebBalance")
    public Result<YebBalancePo> getYebBalance(QueryParameterDto queryParameterDto) {
        try {
            return service.getYebBalance(queryParameterDto);
        } catch (Exception e) {
            log.error(e.getMessage());
            Result<YebBalancePo> result = new Result<>();
            result.setCode(500);
            result.setMessage("获取失败");
            return result;
        }
    }

    @ApiOperation(value = "获取余额宝余额")
    @ApiImplicitParams(
            {
                    @ApiImplicitParam(name = "userId", value = "用户id", required = true, dataType = "String"),
                    @ApiImplicitParam(name = "token", value = "token", required = true, dataType = "String"),
                    @ApiImplicitParam(name = "page", value = "页 默认传1", required = true, dataType = "String"),
                    @ApiImplicitParam(name = "type", value = "状态 0 正常 1 结束", required = true, dataType = "String"),
                    @ApiImplicitParam(name = "忽略非必填字段", value = "", required = false)
            }
    )
    @GetMapping(value = "/getFinancialOrderList")
    public Result<FinancialOrderPo> getFinancialOrderList(QueryParameterDto queryParameterDto) {
        try {
            return service.getFinancialOrderList(queryParameterDto);
        } catch (Exception e) {
            log.error(e.getMessage());
            Result<FinancialOrderPo> result = new Result<>();
            result.setCode(500);
            result.setMessage("获取失败");
            return result;
        }
    }

    @ApiOperation(value = "获取周期列表")
    @GetMapping(value = "/getCycleList")
    public Result<List<XgbFinancialCycle>> getCycleList() {
        try {
            return service.getCycleList();
        } catch (Exception e) {
            log.error(e.getMessage());
            Result<List<XgbFinancialCycle>> result = new Result<>();
            result.setCode(500);
            result.setMessage("获取失败");
            return result;
        }
    }
}
